'''

'''

import tkinter as tk


window = tk.Tk()
window.title('我的窗口')
window.geometry('500x300') # 窗体的大小
# 标签
var = tk.StringVar()
label = tk.Label(window, textvariable=var, bg='green', font=('Arial', 12), width=15, height=2)
# label.pack() # 标签的位置, 自动居中
label.place(x=20, y=20) # 标签的位置, 手动指定
# label.grid(row=0, column=0) # 标签的位置, 网格布局

on_hit = False

def hit_me(event):
    global on_hit
    if on_hit == False:
        on_hit = True
        var.set('you hit me')
    else:
        on_hit = False
def change_red(event):
    label.config(bg='red')

def change_blue(event):
    label.config(bg='blue')

def clear_text(event):
    var.set('')
    on_hit = False

label.bind('<Button-1>', hit_me) # 左键点击
label.bind('<Button-2>', hit_me) # 中键点击
label.bind('<Button-3>', clear_text) # 右键点击
label.bind('<Double-Button-1>', clear_text) # 左键双击
label.bind('<Double-Button-2>', hit_me) # 中键双击
label.bind('<Double-Button-3>', hit_me) # 右键双击
label.bind('<Triple-Button-1>', hit_me) # 左键三击
label.bind('<Triple-Button-2>', hit_me) # 中键三击
label.bind('<Triple-Button-3>', hit_me) # 右键三击
label.bind('<Enter>', change_red) # 鼠标进入
label.bind('<Leave>', change_blue) # 鼠标离开

def hit_me2():
    global on_hit
    if on_hit == False:
        on_hit = True
        var.set('you hit me')
    else:
        on_hit = False
        var.set('')

button = tk.Button(window, text="hit_me", width=15, height=2, command=hit_me2)
button.pack()

# 按钮
button = tk.Button(window, text='quit', width=15, height=2, command=window.quit)
button.pack()

window.mainloop()